<template>
  <div ref="scatter"></div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: 'Scatter',
  data() {
    return {
      echarts: null,
      options: {
        dataZoom: [
          {
            type: 'slider',
            xAxisIndex: 0,

            // 百分比初始
            start: 0,
            // 百分比结束
            end: 100
          },
          {
            type: 'slider',
            yAxisIndex: 0,
            top: 60,
            bottom: 100
          }
        ],
        xAxis: {
          name: '电导率',
          type: 'value',
        },
        yAxis: {
          name: '浑浊度',
          type: 'value',
          // position: 'right'
        },
        tooltip: {
          formatter: params => `${this.options.xAxis.name}: ${params.value[0]}<br/>${this.options.yAxis.name}: ${params.value[1]}`
        },
        series: [
          {
            name: '电导率与浑浊度',
            data: [
              [1, 3], [2, 4], [6, 8], [2, 5], [2, 4], [7, 3],
              [1, 5], [6, 4], [5, 5], [4, 2], [3, 7], [6, 6],
            ],
            type: 'scatter',
            // 散点大小
            // symbolSize(params) {
            //   console.log(params)
            // }
            symbolSize: 10,
            itemStyle: {
              color(params) {
                if (params.value[0] >= 5)
                  return 'green'
                return 'blue'
              }
            }
          }
        ]
      }
    }
  },
  mounted() {
    this.echarts = echarts.init(this.$refs.scatter)
    this.echarts.setOption(this.options)
  },
}
</script>

<style scoped>

</style>
